<template>
  <div>
    <input type="file" @change="changeImagae" />
    <button @click="upload">upload</button>
    预览
    <img :src="image" alt="" v-if="image" />
  </div>
</template>
<script>
import { uploadImage } from './util/upload'
export default {
  data () {
    return { image: "", file: null, token: null }
  },
  methods: {
    async upload () {
      var self = this
      if (this.file) {
        uploadImage(this.file).then((res) => {
          if (res.path) {
            self.image = res.path
          }
        })
      }
    },
    changeImagae (e) {
      this.file = e.target.files[0]
    }
  }
}</script>